/**
 * Created by Francis.LW on 2017/10/20.
 *
 * 事故上报服务接口
 */
import {postRequest, getRequest} from '@/common/request'
import {urls} from './url'

const accidentReportApi = urls.accidentReport
const baseUrl = accidentReportApi.baseUrl
const action = accidentReportApi.action

function list(param, page, pageSize, success, complete) {
  postRequest(baseUrl + action.list + '?currentpage=' + page + '&pagesize=' + pageSize, {}, param, success, complete)
}

function listServiceAccidentReport(param, page, pageSize, success, complete) {
  postRequest(baseUrl + action.listServiceAccidentReport + '?currentpage=' + page + '&pagesize=' + pageSize, {}, param, success, complete)
}


function reachAccidentScene(param, success, complete) {
  postRequest(baseUrl + action.reachAccidentScene, {}, param, success, complete)
}

function lossAssessment(param, success, complete) {
  postRequest(baseUrl + action.lossAssessment, {}, param, success, complete)
}

function closeCase(param, success, complete) {
  postRequest(baseUrl + action.closeCase, {}, param, success, complete)
}

function cancelAccident(param, success, complete) {
  postRequest(baseUrl + action.cancelAccident, {}, param, success, complete)
}

function get(id, success, complete) {
  getRequest(baseUrl + action.get + id, {}, success, complete)
}

function getAccidentReportProcess(id, success, complete) {
  getRequest(baseUrl + action.getAccidentReportProcess + id, {}, success, complete)
}

function remove(ids, success, complete) {
  postRequest(baseUrl + action.remove, {}, ids, success, complete)
}

/**
 *
 * @param ids
 * @param success
 * @param complete
 */
function deleteSingleAccidentReport(id, success, complete) {
  let ids = []
  ids.push(id)
  remove(ids, success, complete)
}

function getAddress(latlnt, success, complete) {
  getRequest('http://api.map.baidu.com/geocoder/v2/?ak=Y3RqwGsCeVUgmLY4UYRFgght&output=json&pois=1&location=' + latlnt, {}, success, complete)
}

export default {
  getAddress,
  listServiceAccidentReport,
  list,
  reachAccidentScene,
  lossAssessment,
  closeCase,
  cancelAccident,
  get,
  getAccidentReportProcess,
  remove,
  deleteSingleAccidentReport
}
